package com.gwtsz.chart.output.utils;

import android.content.res.TypedArray;

import com.gwtsz.chart.R;

import www.com.library.app.AppActivities;


/**颜色类**/
public class ChartThemeUtil {

	private static final int[] ATTRS = new int[]{
			R.attr.theme_color_bg,
			R.attr.theme_color_text,
			R.attr.theme_color_line,
			R.attr.theme_color_cursor_text,
			R.attr.theme_color_time_lines,
			R.attr.theme_color_time_shadow,
			R.attr.theme_color_avg_line,
			R.attr.theme_color_chart_rise,
			R.attr.theme_color_chart_fall,
			R.attr.theme_color_chart_unchang,
			R.attr.theme_color_chart_cursor,
			R.attr.theme_color_chart_line_1,
			R.attr.theme_color_chart_line_2,
			R.attr.theme_color_chart_line_3,
			R.attr.theme_color_chart_line_4,
			R.attr.theme_color_chart_line_5,
			R.attr.theme_color_chart_line_6,
			R.attr.theme_color_chart_price,
	};

	public int RiseColor ;//上涨颜色值
	public int FallColor ;//下跌颜色值
	public int IdleColor;// 持平颜色值
//	<!--背景-->
	public int color_bg;
//	<!--页面默认色最常没作特别要求的字体-->
	public int color_text;
//	<!--所有下划线色，分线及点击行背景效果-->
	public int color_line;
//	<!--tab背景，用到全白的文字及背景,图表弹出菜单字体色-->
	public int color_cursor_text;
//	<!--分时主线-->
	public int color_time_line;
//	<!--分时阴影-->
	public int color_time_shadow;
//	<!--分时均线-->
	public int color_avg_line;

//	<!--绿涨-->
	public int color_chart_rise;
//	<!--红跌-->
	public int color_chart_fall;
//	<!--不涨不跌灰-->
	public int color_chart_unchang;
//	<!--K线主线色，光标颜色-->
	public int color_chart_cursor;
//	<!--K线现价线-->
	public int color_chart_price;

//	<!--ma5-->
	public int color_chart_line_1;
//	<!--ma10-->
	public int color_chart_line_2;
//	<!--ma20-->
	public int color_chart_line_3;
//	<!--ma30-->
	public int color_chart_line_4;
//	<!--ma60-->
	public int color_chart_line_5;
//	<!--ma90-->
	public int color_chart_line_6;

	public boolean isGreenRise = true;
	private static ChartThemeUtil mInstance;

	public static ChartThemeUtil instance(){
		if(null == mInstance){
			mInstance = new ChartThemeUtil();
		}

		return mInstance;
	}


	/**
	 * 设置红涨绿跌，绿涨红跌配置
	 * @param isGreenRise
	 */
	public void setColorConfig(boolean isGreenRise){
		if(isGreenRise){
			mInstance.defaultColorTheme();
		}else{
			mInstance.changeColorTheme();
		}
	}

	public void defaultColorTheme(){
		final TypedArray a = AppActivities.getSingleton().currentActivity().obtainStyledAttributes(ATTRS);
		color_bg = a.getColor(0,0);
		color_text = a.getColor(1,0);
		color_line = a.getColor(2,0);
		color_cursor_text = a.getColor(3,0);
		color_time_line = a.getColor(4,0);
		color_time_shadow = a.getColor(5,0);
		color_avg_line = a.getColor(6,0);
		color_chart_rise = a.getColor(7,0);
		color_chart_fall = a.getColor(8,0);
		color_chart_unchang = a.getColor(9,0);
		color_chart_cursor = a.getColor(10,0);
		color_chart_line_1 = a.getColor(11,0);
		color_chart_line_2 = a.getColor(12,0);
		color_chart_line_3 = a.getColor(13,0);
		color_chart_line_4 = a.getColor(14,0);
		color_chart_line_5 = a.getColor(15,0);
		color_chart_line_6 = a.getColor(16,0);
		color_chart_price = a.getColor(17,0);
		RiseColor = a.getColor(7,0);
		FallColor = a.getColor(8,0);
		IdleColor = a.getColor(9,0);
		isGreenRise = true;
		a.recycle();
	}

	public void changeColorTheme(){
		final TypedArray a = AppActivities.getSingleton().currentActivity().obtainStyledAttributes(ATTRS);
		color_bg = a.getColor(0,0);
		color_text = a.getColor(1,0);
		color_line = a.getColor(2,0);
		color_cursor_text = a.getColor(3,0);
		color_time_line = a.getColor(4,0);
		color_time_shadow = a.getColor(5,0);
		color_avg_line = a.getColor(6,0);
		color_chart_rise = a.getColor(7,0);
		color_chart_fall = a.getColor(8,0);
		color_chart_unchang = a.getColor(9,0);
		color_chart_cursor = a.getColor(10,0);
		color_chart_line_1 = a.getColor(11,0);
		color_chart_line_2 = a.getColor(12,0);
		color_chart_line_3 = a.getColor(13,0);
		color_chart_line_4 = a.getColor(14,0);
		color_chart_line_5 = a.getColor(15,0);
		color_chart_line_6 = a.getColor(16,0);
		color_chart_price = a.getColor(17,0);
		FallColor = a.getColor(7,0);
		RiseColor = a.getColor(8,0);
		IdleColor = a.getColor(9,0);
		isGreenRise = false;
		a.recycle();
	}
}
